const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('m_regions', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true,
      comment: '区域编号'
    },
    name: {
      type: DataTypes.STRING(60),
      allowNull: true,
      comment: '区域名称'
    },
    statis_code: {
      type: DataTypes.STRING(12),
      allowNull: true,
      comment: '区域国标编码'
    },
    code: {
      type: DataTypes.STRING(6),
      allowNull: true,
      comment: '区域编码'
    },
    full_name: {
      type: DataTypes.STRING(400),
      allowNull: true,
      comment: '区域全称'
    },
    region_type: {
      type: DataTypes.TINYINT,
      allowNull: true,
      comment: '类型'
    },
    sort: {
      type: DataTypes.TINYINT,
      allowNull: true,
      defaultValue: 0,
      comment: '排列顺序'
    },
    parent_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '上级对象编号'
    },
    is_del: {
      type: DataTypes.TINYINT,
      allowNull: true,
      defaultValue: 0,
      comment: '是否删除'
    }
  }, {
    sequelize,
    tableName: 'm_regions',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: 'PRIMARY',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'id' }
        ]
      },
      {
        name: 'idx_parentID',
        using: 'BTREE',
        fields: [
          { name: 'region_type' },
          { name: 'parent_id' }
        ]
      },
      {
        name: 'idx_code',
        using: 'BTREE',
        fields: [
          { name: 'code' }
        ]
      }
    ]
  });
};
